<?php
//memasukkan class ke dalam script
require_once('../xlsClass/OLEwriter.php');
require_once('../xlsClass/BIFFwriter.php');
require_once('../xlsClass/Worksheet.php');
require_once('../xlsClass/Workbook.php');
//koneksi database, sesuaikan dengan host,username dan password database anda
function open_connect() {
$host="localhost";
$usrname="root";
$usrpwd="";
$dbname="coba";
$link=mysql_connect($host,$usrname,$usrpwd) or die ("Database tidak dapat
dihubungkan!");
mysql_select_db($dbname,$link);
return $link;
}
function HeaderingExcel($filename){
header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:attachment;filename=$filename");
header("Expires:0");
header("Cache-Control:must-revalidate,post-check=0,pre-check=0");
header("Pragma: public");
}
//Tempatkan query anda disini (harus "SELECT")
$sql="SELECT * FROM login";
$link=open_connect();
$qry=mysql_query($sql,$link) or die ("Invalid Query");
//nama file yang dihasilkan adalah 'xxx.xls'
HeaderingExcel('xxx.xls');
//membuat area kerja
$workbook=new Workbook("-");
//class untuk mencetak tulisan besar dan tebal
$fBesar=& $workbook->add_format();
$fBesar->set_size(14);
$fBesar->set_bold();
//class untuk mencetak tulisan tanpa border (untuk judul laporan)
$fList=& $workbook->add_format();
$fList->set_border(0);
//class untuk mencetak tulisan dengan border dan ditengah kolom (untuk judul kolom)
$fDtlHead=& $workbook->add_format();
$fDtlHead->set_border(1);
$fDtlHead->set_align("center");
//class untuk mencetak tulisan dengan border (untuk detil laporan bernilai string)
$fDtl=& $workbook->add_format();
$fDtl->set_border(1);
//class untuk mencetak tulisan dengan border (untuk detil laporan bernilai numerik)
$fDtlNumber=& $workbook->add_format();
$fDtlNumber->set_border(1);
$fDtlNumber->set_align("right");
$fDtlNumber->set_num_format(3);
//class untuk men-zoom laporan 75%
$worksheet1= & $workbook->add_worksheet("Sheet 1");
$worksheet1->set_zoom(75);
//class untuk men-set page orientation ke landscape
$worksheet1->set_landscape(75);
//class untuk mengatur margin kertas
$worksheet1->set_margin_left(0.2);
$worksheet1->set_margin_top(0.2);
$worksheet1->set_margin_right(0.5);
$worksheet1->set_margin_bottom(0.5);
//class untuk men-set jenis kertas (1=letter, 9=A4)
$worksheet1->set_paper(1);
//class untuk menyembunyikan gridline
$worksheet1->hide_gridlines();
//class untuk men-set area print (baris mulai, kolom mulai, baris akhir, kolom akhir) dimulai dari 0
$worksheet1->print_area(0,0,40,8);
//mengatur lebar kolom (baris, kolom, lebar kolom)
//sesuaikan dengan kolom pada table anda
$worksheet1->set_column(0,0,3);
$worksheet1->set_column(0,1,30);
$worksheet1->set_column(0,2,15);
$worksheet1->set_column(0,3,25);
$worksheet1->set_column(0,4,25);
$worksheet1->set_column(0,5,25);
$worksheet1->set_column(0,6,30);
$worksheet1->set_column(0,7,5);
//sesuaikan dengan judul kolom pada table anda
$worksheet1->write_string(0,3,"DAFTAR DETIL DELIVERY ORDER",$fBesar);
$worksheet1->write_string(1,0,"Periode : ",$fList);
$worksheet1->write_string(2,0,"No.",$fDtlHead);
$worksheet1->write_string(2,1,"Customer",$fDtlHead);
$worksheet1->write_string(2,2,"Tgl / No.",$fDtlHead);
$worksheet1->write_string(2,3,"Item",$fDtlHead);
$worksheet1->write_string(2,4,"Dim",$fDtlHead);
$worksheet1->write_string(2,5,"HS / Warna",$fDtlHead);
$worksheet1->write_string(2,6,"Keterangan",$fDtlHead);
$worksheet1->write_string(2,7,"Qty",$fDtlHead);
//looping record dimulai dari baris ketiga
//sesuaikan dengan field pada table anda
$baris=3;
$nomor=1;
while($rowdtl=mysql_fetch_object($qrydtl)) {
$worksheet1->write_string($baris,0,$nomor,$fDtlHead);
$worksheet1->write_string($baris,1,$rowdtl->xxx,$fDtl);
$worksheet1->write_string($baris,2,$rowdtl->xxx,$fDtl);
$worksheet1->write_string($baris,3,$rowdtl->xxx,$fDtl);
$worksheet1->write_string($baris,4,$rowdtl->xxx,$fDtl);
$worksheet1->write_string($baris,5,$rowdtl->xxx,$fDtl);
$worksheet1->write_string($baris,6,$rowdtl->xxx,$fDtl);
$worksheet1->write_string($baris,7,$rowdtl->xxx,$fDtlHead);
//$baris=$baris+2;
$baris=$baris+1;
$nomor=$nomor+1;
}
$workbook->close();
?>